package com.gxa.saas.portal.controller;


import com.gxa.saas.portal.service.ClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Api(value = "c端分类详情模块")
@Controller
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    @ApiOperation("分类+综合查询")
    @ResponseBody
    @GetMapping("/Classify/ClaSyselect")
    public Map ClaSyselect(@RequestParam("firstName") String firstName,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (StringUtils.isEmpty(firstName)){
            map.put("code",400);
            map.put("message","firstName参数错误");
            return map;
        }
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        map =  this.classifyService.ClaSyselect(firstName,pageNumber,pageSize);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("分类+价格查询")
    @ResponseBody
    @GetMapping("/Classify/ClaMoneySelect")
    public Map ClaMoneyselect(@RequestParam("firstName") String firstName,@RequestParam("value") Integer value,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (StringUtils.isEmpty(firstName)){
            map.put("code",400);
            map.put("message","firstName参数错误");
            return map;
        }
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        if (value==null){
            map.put("code",400);
            map.put("message","value参数错误");
            return map;
        }
       map =  this.classifyService.ClaMoneyselect(firstName,value,pageNumber,pageSize);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

    @ApiOperation("分类+销量查询")
    @ResponseBody
    @GetMapping("/Classify/ClaSalesSelect")
    public Map ClaSalesSelect(@RequestParam("firstName") String firstName,@RequestParam("value") Integer value,@RequestParam Integer pageNumber,@RequestParam Integer pageSize){
        Map map = new HashMap();
        if (StringUtils.isEmpty(firstName)){
            map.put("code",400);
            map.put("message","firstName参数错误");
            return map;
        }
        if (pageNumber==null){
            map.put("code",400);
            map.put("message","pageNumber参数错误");
            return map;
        }
        if (pageSize==null){
            map.put("code",400);
            map.put("message","pageSize参数错误");
            return map;
        }
        if (value==null){
            map.put("code",400);
            map.put("message","value参数错误");
            return map;
        }
        map =  this.classifyService.ClaSalesSelect(firstName,value,pageNumber,pageSize);
        if (MapUtils.isEmpty(map)){
            map.put("code","300");
            map.put("message","无数据");
            return map;
        }
        return map;
    }

}
